<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_ELECTRIC extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table  = "M_ELECTRIC";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey   = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "id";
	 
	 protected $_cols  = array(
		"electric_name"    => array(AOKI_VARTYPE_STR),
	 );
	
	 protected $_checks  = array(
		"electric_name"  => array( "EXIST" ),
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"electric_name "    => 50 
	 );
	
	 public function search($where ,&$page = NULL, $userid = NULL ){
		$sql = "SELECT a.*,(select  user_name FROM M_LOGIN where id  = a.u_user) as m_user_name from {$this->_table}  a ";
		if (!empty($userid)) {
			$sql = $sql. " inner join M_LOGIN b on b.electric_id =a.id where b.id ='{$userid}'";
		}
		return  parent::search($where ,$page ,$sql);
	}
	
	
	public function getShopCount($value) {
		$sql = "SELECT count(*)  as cnt FROM M_ELECTRIC_SHOP WHERE electric_id = '{$value}'";
		$this->_db->query( $sql );
		if( $this->_db->num_rows() ){
			$row = $this->_db->fetch();
			return $row["cnt"];
		}else{
			return  null;
		}
	}
}

?>